package org.wkg.lesson12;

import java.util.concurrent.TimeUnit;

public class Demo_1203 {

    public static void main(String[] args) {

        Object locker1 = new Object();
        Object locker2 = new Object();

        Thread t1 = new Thread(() -> {
            System.out.println("t1申请locker1");
            synchronized (locker1) {
                System.out.println("t1获取到了locker1");
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                synchronized (locker2) {
                    System.out.println("t1获取到了所有锁资源");
                }
            }
        });

        Thread t2 = new Thread(() -> {
            System.out.println("t2申请locker1");
            synchronized (locker1) {
                System.out.println("t2获取到了locker1");
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                synchronized (locker2) {
                    System.out.println("t2获取到了所有锁资源");
                }
            }
        });
        t1.start();
        t2.start();
    }
}
